package com.skyolder.milkbee.web.rest.my;

import com.codahale.metrics.annotation.Timed;
import com.skyolder.milkbee.domain.Card;
import com.skyolder.milkbee.domain.Comment;
import com.skyolder.milkbee.domain.Leaguer;
import com.skyolder.milkbee.domain.Moderator;
import com.skyolder.milkbee.domain.User;
import com.skyolder.milkbee.dto.SimpleResult;
import com.skyolder.milkbee.service.CardService;
import com.skyolder.milkbee.service.CommentService;
import com.skyolder.milkbee.service.LeaguerService;
import com.skyolder.milkbee.service.ModeratorService;
import com.skyolder.milkbee.service.UserService;
import com.skyolder.milkbee.security.SecurityUtils;
import com.skyolder.milkbee.web.rest.util.HeaderUtil;
import com.skyolder.milkbee.web.rest.util.PaginationUtil;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.inject.Inject;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * REST controller for managing Comment.
 */
@RestController("myCommentResource")
@RequestMapping("/api/my")
public class CommentResource {

	private final Logger log = LoggerFactory.getLogger(CommentResource.class);

	@Inject
	private CommentService commentService;
	@Inject
	private UserService userService;

	@GetMapping("/comment")
	@Timed
	public ResponseEntity<List<Comment>> getMyComments(@ApiParam Pageable pageable) throws URISyntaxException {
		Optional<User> ouser = userService.getUserWithAuthoritiesByLogin(SecurityUtils.getCurrentUserLogin());
		User user = ouser.get();
		Long userId = user.getId();
		Page<Comment> page = commentService.findByUserId(userId, pageable);
		HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/mycomment");
		return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
	}

}
